*Structural-Analysis99.do
****************************************************************************************
**************************Analysis for 1999*********************************************
****************************************************************************************
 clear matrix

*
*log using "C:\Selfemployment\Self-Employment\selfemployment.smcl", replace
clear
set mem 300000
set matsize 800

set more off

*****************This Do-File Runs The Heckman Two-Step Selection Model*****************
*****************Note: Heckman Procedure Uses Reduced-Form Probit***********************

do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\Selection-Probit_99_df.do"

*****************This Files Run the CTaCS Program***************************************
*****************Note: WS = Wage/Salary SE = Self-Employment Real = Sample *************

do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsWS99.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSE99.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsReal99.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSED99.do"
do  "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\ctacsSEH99.do"


***************************Merge CTaCS Output to Master Data****************************


use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-99ws.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxWS 
rename totprovtax totprovtaxWS 
rename tottax tottaxWS

keep pucpid26 totfedtaxWS totprovtaxWS tottaxWS

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsWS.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-99se.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSE 
rename totprovtax totprovtaxSE 
rename tottax tottaxSE

keep pucpid26 totfedtaxSE totprovtaxSE tottaxSE

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsSE.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-99real.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxReal 
rename totprovtax totprovtaxReal
rename tottax tottaxReal

keep pucpid26 totfedtaxReal totprovtaxReal tottaxReal

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsReal", replace

**********
use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-99SED.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSED 
rename totprovtax totprovtaxSED 
rename tottax tottaxSED

keep pucpid26 totfedtaxSED totprovtaxSED tottaxSED

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsSED.dta", replace

use "/Users/mdgordon/Desktop\Selfemployment\Ctacs\CTaCS-2008-1\inout\ctacs-99SEH.dta", clear

rename id pucpid26 
rename totfedtax totfedtaxSEH 
rename totprovtax totprovtaxSEH 
rename tottax tottaxSEH

keep pucpid26 totfedtaxSEH totprovtaxSEH tottaxSEH

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsSEH.dta", replace
***********************
use "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99analysis", clear

sort pucpid26
*drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsWS"
tab _merge
drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsSE"
tab _merge
drop _merge

merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsReal"
tab _merge
drop _merge
**********
merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsSED"
tab _merge
drop _merge
*
merge using "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99ctacsSEH"
tab _merge
drop _merge
**************

*log using "C:\Selfemployment\Self-Employment\selfemployment.smcl", replace

**************Summarize Predicted Earnings and Predicted Taxes**********************

sum  btearningSE btearningE 
bysort selfemp:  sum earng42

sum  tottaxWS tottaxSE tottaxReal tottaxSED tottaxSEH
bysort selfemp: sum inctx27 
sum inctx27 

sum  tottaxWS tottaxSE tottaxReal if inva27==0 & male==1
bysort selfemp: sum inctx27 if inva27==0 & male==1
sum inctx27 if inva27==0 & male==1


*
gen taxdif=  ln((tottaxSE )/(tottaxWS))
gen taxdifDH=1  

gen taxU=(tottaxSED)/(tottaxSE)
gen Tax_ratio = (tottaxSE/(btearningSE+other-tottaxSE))
*sum Tax_ratio  if Tax_ratio>0 & Tax_ratio<1
gen taxdifU=  ln(taxU)*Tax_ratio
gen taxdifU2= (taxU-1)*Tax_ratio

replace tottaxSEH=1 if tottaxSEH==0
gen taxD = (tottaxSEH)/(tottaxSE)
*gen taxD = (tottaxSE)/(tottaxSEH)
gen taxdifD = ln(taxD)*Tax_ratio
gen taxdifD2 = (taxD-1)*Tax_ratio


sum  tottaxSED tottaxSEH tottaxSE if tottaxSEH>0 & tottaxSE>0
drop if tottaxSEH<=0 | tottaxSE<=0  
sum  tottaxSED tottaxSEH tottaxSE  


* Keeping only variables to be used in final   model
keep date Tax_ratio other other2 rse  DhhE  inctx42 fditx42 pvitx42 inctx27 wkrcp42 spoucearn btearningE btearningSE  incomedif  year pucpid26 puchid25 selfemp inva27 inva42 capgn27   yrschl18 ecage26 age2 wksuem28 health male married   kids immigrant blucol   service newfoundland pei novascotia newbrunswick ontario quebec manitoba saskatchewan alberta bc earng42  wksuem28 udpd42 medx42 rppc42 rspwi42 pen42 oasgi42 cpqpp42 uiben42 capgn27 capgn42 sapis42 ottxm42 cpqpp42 alimo42 rppc42 chfed42 ccar42 alip42 year  kidage1-kidage7 rd yrxfte11  pctincearn whtcol incomedif  taxdif taxdifU taxdifU2 taxdifD taxdifD2 taxdifDH totfedtaxWS totprovtaxWS tottaxWS totfedtaxSE totprovtaxSE tottaxSE totfedtaxReal totprovtaxReal tottaxReal    
 
*SEstdf
*yrxfte11
 
 

save "/Users/mdgordon/Desktop\Selfemployment\Self-Employment\99analysis", replace

 




  

